﻿
@{
	Layout = null;
}

<!DOCTYPE html>

<html>
<head>
	<meta name="viewport" content="width=device-width" />
	<title>UpdateUserInfoView</title>
	<link href="~/layuimini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
	<link href="~/layuimini/css/public.css" rel="stylesheet" />
</head>
<body>
	<form class="layui-form" action="" lay-filter="formTest">
		<div class="layui-form-item" hidden>
			<label class="layui-form-label">ID</label>
			<div class="layui-input-block">
				<input type="text" name="ID" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input type="text" name="Title" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">描述</label>
			<div class="layui-input-block">
				<input type="text" name="Description" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">等级</label>
			<div class="layui-input-block">
				<input type="text" name="Level" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-block">
				<input type="text" name="Sort" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">访问地址</label>
			<div class="layui-input-block">
				<input type="text" name="Href" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">父菜单id</label>
			<div class="layui-input-block">
				<select name="ParentId" id="menuSelect">
					<option value=""></option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图标样式</label>
			<div class="layui-input-block">
				<input type="text" name="Icon" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">目标</label>
			<div class="layui-input-block">
				<input type="text" name="Target" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
			</div>
		</div>
	</form>
	<script src="~/layuimini/lib/layui-v2.6.3/layui.js"></script>

	<script>
		//Demo
		layui.use(['form'], function () {
			var form = layui.form,
				layer = layui.layer,
				$ = layui.$;

			if (parent.menuInfoId) {
				//异步获取菜单下拉框数据集合

				$.ajax({
                    url: 'http://localhost:31861/api/MenuInfo/GetUpdateMenuInfo',
					type: 'get',
					data: { menuInfoId: parent.menuInfoId },
					success: function (res) {

						//追加新的下拉选数据
						if (res.datas && res.datas.options.length > 0) {
							for (var i = 0; i < res.datas.options.length; i++) {
								$('#menuSelect').append('<option value="' + res.datas.options[i].id + '">' + res.datas.options[i].title + '</option>');
							}
							form.render('select'); //刷新select选择框渲染
						}

						//表单赋值
						form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
							"ID": res.datas.menuInfo.id
							, "Title": res.datas.menuInfo.title
							, "Describe": res.datas.menuInfo.describe
							, "Level": res.datas.menuInfo.level
							, "Sort": res.datas.menuInfo.sort
							, "Href": res.datas.menuInfo.href
							, "ParentId": res.datas.menuInfo.parentId
							, "Icon": res.datas.menuInfo.icon
							, "Target": res.datas.menuInfo.target
						});
					}
				});
			}

			//监听提交
			form.on('submit(formDemo)', function (data) {
				var index = layer.alert('确认提交', {
					title: '提示'
				}, function () {
					console.log(parent);


					//异步请求保存用户信息
					$.ajax({
                        url: "http://localhost:31861/api/MenuInfo/UpdateMenuInfo",
						data: data.field,
						type: "post",
						success: function (res) {
							if (res.isSuccess) {


								//关闭弹出层
								layer.close(index);
								var iframeIndex = parent.layer.getFrameIndex(window.name);
								parent.layer.close(iframeIndex);
								//调用父级页面的刷新方法
								parent.reLoadTable();
								//其他业务
							} else {
								layer.msg(res.msg);
							}
						}
					});
				});
				return false;
			});
		});
	</script>


</body>
</html>
